package com.orange.cetback.controller.user;

import com.orange.cetback.common.vo.PageResult;
import com.orange.cetback.common.vo.Result;
import com.orange.cetback.pojo.dto.QueryWordDTO;
import com.orange.cetback.pojo.dto.StudyWordDTO;
import com.orange.cetback.pojo.dto.UnreviewedWordsDTO;
import com.orange.cetback.pojo.entity.Cet4Word;
import com.orange.cetback.pojo.entity.UserWordReview;
import com.orange.cetback.pojo.vo.StudyWordVO;
import com.orange.cetback.service.Cet4WordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author chenenjun
 * @since 2025-02-18
 */
@Slf4j
@RestController
@RequestMapping("/userApi/cet4Word")
@Tag(name = "CET4单词接口")
public class Cet4WordController {

    @Autowired
    private Cet4WordService cet4WordService;

    @Operation(summary = "分页查询单词")
    @GetMapping("/word")
    public Result<PageResult<Cet4Word>> getWordPage(QueryWordDTO queryWordDTO) {
        log.info("分页查询单词,参数:{}", queryWordDTO);
        PageResult<Cet4Word> pageResult = cet4WordService.pageQuery(queryWordDTO);
        return Result.success(pageResult);
    }

    @Operation(summary = "查询背诵单词")
    @GetMapping("/study")
    public Result<PageResult<StudyWordVO>> studyWord(UnreviewedWordsDTO unreviewedWordsDTO) {
        PageResult<StudyWordVO> pageResult = cet4WordService.getUnreviewedWords(unreviewedWordsDTO);
        return Result.success(pageResult);
    }






    // Cet4WordController.java 新增接口
    @Operation(summary = "批量更新发音文件")
    @GetMapping("/updateAudio")
    public Result<String> updateAudioUrls(
            @RequestParam Integer startId,
            @RequestParam Integer endId) {
        cet4WordService.batchUpdateAudioUrls(startId, endId);
        return Result.success("音频文件更新任务已启动");
    }
}
